﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using System.Web.UI.HtmlControls;
namespace web.admin.prTask
{
    public partial class OutterReport : System.Web.UI.Page
    {
        private AcademyService academyService = new AcademyService();
        private CompetitionService competitionService = new CompetitionService();
        private ContestService contestService = new ContestService();
        const int pagesize = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Rp_Bind();
            }
        }
        /// <summary>
        /// repeater控件绑定
        /// </summary>
        protected void Rp_Bind()
        {
            Pager1.PageSize = pagesize;
            int records = 0;
            if (Request.QueryString["PageCode"] != "fee")
            {
                RpList.DataSource = contestService.GetPagerInnerContests(" COM_TYPE=1", " CON_ID DESC", Pager1.PageSize, Pager1.PageIndex, out records);
                RpList.DataBind();
            }
            else
            {
                RpList.DataSource = contestService.GetPagerInnerContests(" COM_TYPE=1 and COM_CAPITAL=1 ", " CON_ID DESC", Pager1.PageSize, Pager1.PageIndex, out records);
                RpList.DataBind();
            }
            //初始化分页条,设置样式
            Pager1.SetPage(records);
            Pager1.ShowPageJump = true;
            Pager1.ShowPageLan = 0; //导航条语言:0=默认，1=中文，2=英语
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rp_DataBind(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                BoContests contest = (BoContests)e.Item.DataItem;
                HtmlTableCell cell = (HtmlTableCell)e.Item.FindControl("Operation");
                String s = Request["PageCode"];
                string feeUrl = "../InnerManage/InnerMoney.aspx?id="; 
                switch (s)
                {
                    case "fee":
                        cell.InnerHtml = "<a href='" + feeUrl + contest.CON_ID +"'>费用管理</a>";
                        break;
                }
                
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int j = 0;
            for (int i = 0; i < RpList.Items.Count; i++)
            {
                string id = ((HiddenField)RpList.Items[i].FindControl("Hf_id")).Value;
                CheckBox cb = (CheckBox)RpList.Items[i].FindControl("CbChoose");
                if (cb.Checked)
                {
                    BoContests contest = contestService.getContest(id);
                    contestService.DeleteContest(contest);
                    j++;
                }
            }
            Response.Write("<script>alert('删除成功，共删除" + j + "条数据');window.location.href='OutterReport.aspx'; </script>");
            return;
        }
    }
}